<?php
ob_clean();
    //include_once 'init.php';
    if(!empty($_POST)){
        $name=$_POST['name'];//标题
        $pid=$_POST['pid'];//类型

            $sql="insert into `cate` (`name`,`pid`) values('$name','$pid')";
            mysqli_query($link,$sql);
            $result=mysqli_affected_rows($link);
            if($result>0){
                echo '<script>alert("分类添加成功");location.href="index.php?c=cate&a=list&admin=1";</script>';die;
            }else{
                echo '<script>alert("分类添加失败");history.go(-1);</script>';die;
            }
    }
    $id=empty($_GET['id'])?0:$_GET['id'];
    $sql="select * from cate where pid=$id";
    $result=mysqli_query($link,$sql);
    while ($arr=mysqli_fetch_assoc($result)) {
        $cate[]=$arr;
        # code...
    }
    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
        echo json_encode($cate);die;
    }
    include(VIEW_PATH.$admin.'layout.html');
?>